home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 February: Tool Chest / Dev.CD Feb 99 TC.toast / What's New? / Development Kits / Mac OS USB v1.1f3 DDK / Examples / PrinterClassDriver / PrinterClassDriver.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-07  |  7.2 KB  |  249 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PrinterClassDriver.h
  3.  
  4.     Contains:    structures for PrinterClass
  5.  
  6.     Version:    
  7.  
  8.     Copyright:    © 1997-1998 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11. #ifndef __PRINTERCLASSDRIVERH__
  12. #define __PRINTERCLASSDRIVERH__
  13.  
  14. #include <MacTypes.h>
  15. #include <Devices.h>
  16. #include <DriverServices.h>
  17. #include <Processes.h>
  18.  
  19. #ifndef __MIXEDMODE__
  20. #include <mixedmode.h>
  21. #endif
  22.  
  23. #include <USB.h>
  24.  
  25. #if DEBUG
  26. #define IF_DEBUG(x)    x
  27. #else
  28. #define IF_DEBUG(x)
  29. #endif
  30.  
  31. #define kStrPrinterClass    "PrinterClass: "
  32. void DriverEntry(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  33. void ExpertNotify(void *exNote);
  34.  
  35. #define kPrinterRetryCount    5
  36.  
  37. /* Move to sys files */
  38. #define kUSBPrintClass 7
  39. #define kUSBPrintSubClass 1
  40.  
  41. #define TRANSFER_SIZE    4096 /* ideally this is the same as VM page size */
  42.  
  43. // section 5.3 USB Device Class Definition for Printing Devices
  44. enum {
  45.     kUSBPrintClassGetDeviceID = 0,
  46.     kUSBPrintClassGetCentronicsStatus = 1,
  47.     kUSBPrintClassSoftReset = 2,
  48.     kUSBPrintClassProtocolReserved = 0,
  49.     kUSBPrintClassProtocolUnidirectional = 1,
  50.     kUSBPrintClassProtocolBidirectional = 2,
  51.     // 3..0xFE reserved for future use
  52.     kUSBPrintClassProtocolVendor = 0xFF
  53. };
  54.  
  55. enum 
  56. {
  57.     kDrvrCentronicsStatus = 3,
  58.     kDrvr1284IdString = 4,
  59.     kDrvrNumDevices = 5,
  60.     kDrvrSoftReset = 6,
  61.     kDrvrPrivateSetStorage = 128
  62. };
  63.  
  64. enum driverstages
  65. {
  66.     kUndefined = 0,
  67.     kNilCompletion,
  68.     kFindInterface,
  69.     kSetInterface,
  70.     kGetConfigurationDescriptor,
  71.     kGetFullConfiguration,
  72.     kGetCapabilityString,
  73.     kDelayGetCapability,
  74.     kGetFullCapabilityString,
  75.     kGetInterface,
  76.     kOpenBulkOutPipe,
  77.     kOpenBulkInPipe,
  78.     kEnterNameRegistry,
  79.  
  80.     kGetCentronicsStatus,
  81.     kDelayGetCentronicsStatus,
  82.  
  83.     kReturnFromDriver = 0x1000,
  84.     kRetryTransaction = 0x2000,
  85.     kAsyncTransaction = 0x4000,
  86.     kTransactionPending = 0x8000
  87. };
  88.  
  89. enum {
  90.     uppIODoneProcInfo = kRegisterBased
  91.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  92.          | REGISTER_RESULT_LOCATION(kRegisterD0)
  93.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(OSErr)))
  94.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(IOParamPtr)))
  95.          | REGISTER_ROUTINE_PARAMETER(3, kRegisterA1, SIZE_CODE(sizeof(DCtlHandle))),
  96.  
  97.     uppQueueUSBReadProcInfo = kCStackBased
  98.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  99.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  100.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  101.  
  102.     uppQueueUSBWriteProcInfo = kCStackBased
  103.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  104.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  105.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  106.  
  107.     uppAbortProcInfo = kCStackBased
  108.          | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
  109.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DriverRefNum)))
  110.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  111.  
  112.     uppControlStatusProcInfo = kCStackBased
  113.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  114.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  115.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *)))
  116. };
  117.  
  118. #if GENERATINGCFM
  119. typedef UniversalProcPtr    QueueUSBReadUPP;
  120. typedef UniversalProcPtr    QueueUSBWriteUPP;
  121. typedef UniversalProcPtr    IODoneUPP;
  122. typedef UniversalProcPtr    AbortUPP;
  123. typedef UniversalProcPtr    ControlStatusUPP;
  124. #else
  125. typedef ProcPtr                QueueUSBReadUPP;
  126. typedef ProcPtr                QueueUSBWriteUPP;
  127. typedef ProcPtr                IODoneUPP;
  128. typedef ProcPtr                AbortUPP;
  129. typedef ProcPtr                ControlStatusUPP;
  130. #endif
  131.  
  132. typedef struct {
  133.     OSErr        err;
  134.     IOParamPtr    pb;
  135.     DCtlPtr        ctl;
  136. } DrvrParams;
  137.  
  138. typedef union {
  139.     char            b;
  140.     struct {
  141.         unsigned    reserved0:2;
  142.         unsigned    paperError:1;
  143.         unsigned    select:1;
  144.         unsigned    notError:1;
  145.         unsigned    reserved1:3;
  146.     } status;
  147. } CentronicsStatusByte;
  148.  
  149. typedef struct usbPrinterPBStruct
  150. {
  151.     //
  152.     //    note: first element must be USBPB pb
  153.     //        since we often cast it to usbPrinterPBStruct
  154.     //
  155.     USBPB                             pb,                    // configuration block
  156.                                     out,                // map client write
  157.                                     in;                    // map client read
  158.     //
  159.     //    optional bulk in pipe
  160.     //
  161.     USBEndPointDescriptorPtr        readDescriptor;        // configuration/interface info
  162.     USBPipeRef                         readPipe;            // USB pipe reference
  163.     QueueUSBReadUPP                    qread,                // queue USB read from 68K
  164.                                     r;
  165.     RoutineDescriptor                qreadRD;            // static descriptor
  166.     DrvrParams                        readDrvr;            // currently active read
  167.     int                                readRetryCount;        // retry transactions
  168.     //
  169.     //    mandatory bulk out pipe
  170.     //
  171.     USBEndPointDescriptorPtr        writeDescriptor;    // configuration/interface info
  172.     USBPipeRef                         writePipe;            // USB pipe reference
  173.     QueueUSBWriteUPP                qwrite,                // queue USB write from 68K
  174.                                     w;
  175.     RoutineDescriptor                qwriteRD;            // static descriptor
  176.     DrvrParams                        writeDrvr;            // currently active read
  177.     int                                writeRetryCount;    // retry transactions
  178.     //
  179.     //    abort/cancel transactions
  180.     //
  181.     AbortUPP                        qabort,                // cancel from 68K DRVR
  182.                                     a;
  183.     RoutineDescriptor                qabortRD;            // static descriptor
  184.     //
  185.     //    status transactions
  186.     //
  187.     ControlStatusUPP                qstatus,            // simple status from 68K DRVR
  188.                                     s;
  189.     RoutineDescriptor                qstatusRD;            // static descriptor
  190.     DrvrParams                        statusDrvr;            // currently active status request
  191.     //
  192.     //    unit table driver names and refNums
  193.     //
  194.     DRVRHeaderHandle                hDrvr;                // detached from class driver resource file
  195.     DriverRefNum                    outRefNum;            // write unit table ref
  196.     DriverRefNum                    inRefNum;            // read unit table ref
  197.     Str255                            driverOutName;        // write driver name in unit table
  198.     Str255                            driverInName;        // read driver name in unit table
  199.     //
  200.     //    device: configuration and interface details
  201.     //
  202.     UInt8                            terminating;        // offline USS-720 device
  203.     USBDeviceRef                    device;                // USB device reference
  204.  
  205.     USBDeviceDescriptor             desc;                // copy for local reference
  206.     USBInterfaceDescriptorPtr        interface;            // copy for local reference
  207.     UInt32                            interfaceOffset;    // result/param for USB calls
  208.     UInt8                            whichAltInterface;
  209.  
  210.     Str255                            name;                // printer name in name registry
  211.  
  212.     unsigned char                    *capabilityString;    // 1284 capability string
  213.     USBConfigurationDescriptorPtr    config;                // USB configuration string
  214.  
  215.     unsigned char                    capability[256];    // capability: try not to fragment storage
  216.     unsigned char                    configuration[256];    // configuration: try not to fragment storage
  217.  
  218.     CentronicsStatusByte            centronics;
  219.     //
  220.     //    we double-buffer i/o requests into our heap, using page aligned blocks
  221.     //
  222.     UInt32                            pageWriteAlignedBufferSize,
  223.                                     pageReadAlignedBufferSize;
  224.     UInt8                            *pageWriteAlignedBuffer,
  225.                                     *pageReadAlignedBuffer,
  226.                                     malignedBuffer[ 3*TRANSFER_SIZE ];    //PrintDriverEntry assumes 3*TRANSFER_SIZE
  227.  
  228.     //
  229.     //    class driver async transactions
  230.     //
  231.     SInt32                            transDepth;            // don't nest transactions
  232.     SInt32                             retryCount;            // automatically retry transactions
  233.  
  234. };
  235.  
  236.  
  237. OSStatus OpenBulkEndpoint(struct usbPrinterPBStruct    *pPrinterPB, UInt32    refCon);
  238. OSStatus Abort( DriverRefNum refNum, struct usbPrinterPBStruct *pPrinterPB );
  239. void     ControlStatusRequests( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  240. void     QueueRead( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  241. void     QueueWrite( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  242.  
  243. void      PrintDriverEntry(USBDeviceRef device,USBDeviceDescriptorPtr desc, USBInterfaceDescriptorPtr pInterface);
  244. OSStatus PrintDriverFinalize( void );
  245.  
  246.  
  247.  
  248.  
  249. #endif //__PRINTERCLASSDRIVERH__